package home.my.base.sql;
import java.lang.annotation.Annotation;
public abstract class AnnotationConditionFactory {
	public static java.util.HashMap<String, AnnotationConditionFactory> factorys 
		= new java.util.HashMap<String, AnnotationConditionFactory> ();
	static{
		factorys.put("SingleOrNull", new SingleOrNullFactory());
		factorys.put("SingleValue", new SingleValueFactory());
	}
	public static boolean couldBuild(Annotation[] annotations){
		
		if(annotations==null || annotations.length==0 ) return false;
		
		for(Annotation annotation:annotations){
			if(factorys.get(annotation.annotationType().getSimpleName())!=null)
				return true;
		}
		return false;
	}
	/**
	 * 根据元数据构造查询条件
	 * @param annotation
	 * @param column
	 * @param value
	 * @return
	 */
	public static AbsCondition buildCondition(Annotation annotation,String column,Object value){
		AnnotationConditionFactory factory = factorys.get(annotation.annotationType().getSimpleName());
		if(factory==null || 
				value==null || 
				(value instanceof String && ((String)value).equals(""))) return null;
		return factory.build(annotation,column, value);
	}
	
	public abstract AbsCondition build(Annotation annotation,String column,Object value);
}
